// pages/home/home.js
const app = getApp();
const { httpServer } = app.globalData;

Page({
  /**
   * 页面的初始数据
   */
  data: {

  },

  isLofin() {
    const userinfo =  wx.getStorageSync("userinfo");
    let isLofin = false;
    if (userinfo) {
      isLofin = true;
    } else {
      wx.showToast({
        mask: true,
        icon: 'error',
        title: '未登录',
        duration: 2000,
      })

      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/login/login',
        })
      }, 2000)
    }
    return isLofin;
  },

  async goDatabase() {
    if (!this.isLofin()) return;
    let result = await httpServer("post", "/api/Photo/listInformation", {  })

    if (result.code != 401) {
      wx.setStorageSync('isTwelve', false);
      wx.navigateTo({
        // url: '/pages/editor/editor'
        url: '/pages/database/database'
      })
    }
  },

  // 新增图片
  async newlyPicture() {
    if (!this.isLofin()) return;
    let result = await httpServer("post", "/api/Photo/listInformation", {  })

    if (result.code != 401) {
      wx.setStorageSync('isTwelve', false);
      wx.navigateTo({
        // url: '/pages/editor/editor'
        url: '/pages/photograph/photograph'
      })
    }
  },

  goMy() {
    if (!this.isLofin()) return;

    wx.navigateTo({
      url: '/pages/my/my'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
})